package analyticsServer.dataLayer;

import java.util.Vector;

import common.rmi.ClientReference;


public class Subscription {
	
	private static long serial=0;
	private ClientReference client;
	private String subscriptionID;
	private Vector <String> eventTypes;
	
	public Subscription(Vector<String> eventTypes, ClientReference client) {
		this.subscriptionID=issueID();
		this.eventTypes=eventTypes;
		this.client=client;
	}
	
	private static String issueID(){
		serial++;
		return String.valueOf(serial);
	}
	
	public String getID(){
		return this.subscriptionID;
	}
	public ClientReference getClient(){
		return client;
	}
	public void activate(){
		for(String eventType :eventTypes){
			DataLayer.addSubscription(eventType,this);
		}
		DataLayer.registerSubscription(subscriptionID, this);
	}
	public void deactivate(){
		for(String eventType :eventTypes){
			DataLayer.removeSubscription(eventType,this);
		}
		DataLayer.cancelSubscription(this);
	}
	
	public String toString(){
		String s="";
		for(String st:eventTypes){
			s+=st+"\n";
		}
		return s;
	}
}
